'use strict'
const path = require('path')
function resolve (dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  publicPath: './',
  outputDir: 'dist',
  assetsDir: 'static',
  css: {
    sourceMap: process.env.NODE_ENV === 'development',
    loaderOptions: {
      scss: {
        // prependData? additionalData?
        prependData: `
          @import "~@/style/mixin.scss";
        `
      }
      // postcss: {
      //   plugins: [
      //     require('autoprefixer')({
      //       overrideBrowserslist: ['last 5 versions']
      //     }),
      //     require('postcss-pxtorem')({
      //       rootValue: 10,
      //       // selectorBlackList: ['ig'],
      //       propList: ['*'],
      //       exclude: /node_modules/
      //     })
      //   ]
      // }
    }
  },
  devServer: {
    port: 9099,
    proxy: {
      '/v2': {
        target: 'https://api.douban.com',
        ws: true,
        changeOrigin: true
      },
      '/broadcast-web': {
        target: 'http://api.tuohongcm.com',
        ws: true,
        changeOrigin: true
      }
    }
  },
  configureWebpack: {
    name: '',
    resolve: {
      alias: {
        '@': resolve('src'),
        '@api': resolve('src/api/api'),
        '@css': resolve('src/assets/css'),
        '@views': resolve('src/views'),
        '@utils': resolve('src/utils')
      }
    }
  },
  chainWebpack (config) {
    // it can improve the speed of the first screen, it is recommended to turn on preload
    config.plugin('preload').tap(() => [
      {
        rel: 'preload',
        fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
        include: 'initial'
      }
    ])

    // when there are many pages, it will cause too many meaningless requests
    config.plugins.delete('prefetch')
  }
}
